package com.lottery.ruok.lottrey.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.fragment.LXCTrendFragment;
import com.lottery.ruok.lottrey.retrofitModule.response.LiuhecaiTrendResponse;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/11/13.
 */

public class LXCTrendAdapter extends BaseAdapter {
    private LXCTrendFragment lxcTrendFragment;
    private ArrayList<LiuhecaiTrendResponse> liuhecaiTrendResponseList;
    public LXCTrendAdapter(LXCTrendFragment lxcTrendFragment, ArrayList<LiuhecaiTrendResponse> liuhecaiTrendResponseList) {
        this.lxcTrendFragment = lxcTrendFragment;
        this.liuhecaiTrendResponseList = liuhecaiTrendResponseList;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(lxcTrendFragment.getActivity()).inflate(R.layout.lxc_item, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        if (lxcTrendFragment.getArguments().getInt("index") == 1) {
            holder.tema.setVisibility(View.GONE);

            holder.no1.setText(liuhecaiTrendResponseList.get(position).getIssue_no());
            holder.total1.setText(liuhecaiTrendResponseList.get(position).getExt().get(0));
            holder.danshuang1.setText(liuhecaiTrendResponseList.get(position).getExt().get(1));
            holder.daxiao1.setText(liuhecaiTrendResponseList.get(position).getExt().get(2));
            holder.qisebo1.setText(liuhecaiTrendResponseList.get(position).getExt().get(3));
        } else if (lxcTrendFragment.getArguments().getInt("index") == 2) {
            holder.zonghe.setVisibility(View.GONE);

            holder.no2.setText(liuhecaiTrendResponseList.get(position).getIssue_no());
            holder.danshuang2.setText(liuhecaiTrendResponseList.get(position).getExt().get(4));
            holder.daxiao2.setText(liuhecaiTrendResponseList.get(position).getExt().get(5));
            holder.hedanshuang2.setText(liuhecaiTrendResponseList.get(position).getExt().get(6));
            holder.hedaxiao2.setText(liuhecaiTrendResponseList.get(position).getExt().get(7));
            holder.daxiaowei2.setText(liuhecaiTrendResponseList.get(position).getExt().get(8));
        }

        return view;
    }

    @Override
    public int getCount() {
        return liuhecaiTrendResponseList.size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }


    static class ViewHolder {
        @BindView(R.id.no1)
        TextView no1;
        @BindView(R.id.total1)
        TextView total1;
        @BindView(R.id.danshuang1)
        TextView danshuang1;
        @BindView(R.id.daxiao1)
        TextView daxiao1;
        @BindView(R.id.qisebo1)
        TextView qisebo1;
        @BindView(R.id.zonghe)
        LinearLayout zonghe;
        @BindView(R.id.no2)
        TextView no2;
        @BindView(R.id.danshuang2)
        TextView danshuang2;
        @BindView(R.id.daxiao2)
        TextView daxiao2;
        @BindView(R.id.hedanshuang2)
        TextView hedanshuang2;
        @BindView(R.id.hedaxiao2)
        TextView hedaxiao2;
        @BindView(R.id.daxiaowei2)
        TextView daxiaowei2;
        @BindView(R.id.tema)
        LinearLayout tema;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
